package example;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class conexion {

	public static Connection obtenerConexion() throws SQLException {

		Connection con = null;
		//Context ctx = null;
		DataSource ds = null;
		try {
			// Get DataSource
	        Context initContext  = new InitialContext();
	        Context envContext  = (Context)initContext.lookup("java:/comp/env");
	        ds = (DataSource)envContext.lookup("jdbc/testdb");
	        
			//Obtener la conexión del Pool 
			con = ds.getConnection();
			System.out.println("Conexión Pool OK =P");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
		
		
		
	}
	
	public static Connection obtenerConexion2() throws SQLException {

		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			con = DriverManager.getConnection("jdbc:mysql://192.168.1.241/ilkoperu","test", "123456");			
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
		
		
	}
}
